package com.poi.qianmi.export;

import com.poi.qianmi.util.RandomValue;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Classname exportApplication
 * @Description 导出基本模板
 * @Date 2019/9/20 9:27 上午
 * @Created by xiaocai
 */
public class ExportApplication {
    public static void main(String[] args) throws Exception {
        SimpleDateFormat dateFormat = new SimpleDateFormat("YYYYMMDDhhmmss");
        String now = dateFormat.format(new Date());
        //导出文件路径
        String basePath = "/Users/xiaocai/文件/";
        //文件名
        String exportFileName = "数据10.xlsx";
//        String[] cellTitle = {"序号","姓名","学号","性别","入学日期"};

        // 声明一个工作薄
        XSSFWorkbook workBook;
        workBook = new XSSFWorkbook();
        // 生成一个表格
        XSSFSheet sheet = workBook.createSheet();
        workBook.setSheetName(0, "学生信息");
        // 创建表格标题行 第一行
//        XSSFRow titleRow = sheet.createRow(0);
//        for(int i=0;i<cellTitle.length;i++){
//            titleRow.createCell(i).setCellValue(cellTitle[i]);
//        }

        //插入需导出的数据
        for (int i = 0; i < 100000; i++) {
            System.out.println(i);
            XSSFRow row = sheet.createRow(i);
            row.createCell(0).setCellValue(RandomValue.getChineseName());
            row.createCell(1).setCellValue(RandomValue.getRoad());
            row.createCell(2).setCellValue("铂金会员");
            row.createCell(3).setCellValue("无");
        }
        File file = new File(basePath + exportFileName);
        //文件输出流
        FileOutputStream outStream = new FileOutputStream(file);
        workBook.write(outStream);
        outStream.flush();
        outStream.close();
        System.out.println("导出2007文件成功！文件导出路径：--" + basePath + exportFileName);
    }
}
